﻿using Admin2024.Domain.Entity.System;
using Admin2024.Domain.IDomainService.System.IRoleService;
using Admin2024.Domain.Interface;
using Admin2024.Domain.ObjValue;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Admin2024.Domain.DomainService.System.RoleService
{
    public class RoleStateManager : IRoleStateManager
    {
        private readonly IRepository<AppRole> _RoleRep = null!;

        private readonly IBaseDomainService<AppRole> baseDomainService = null!;

        public RoleStateManager(IRepository<AppRole> repository , IBaseDomainService<AppRole> baseDomainService ) {
            _RoleRep = repository;  
            this.baseDomainService = baseDomainService;
        }
        //删除角色
        public async Task<DomainResult<AppRole>> DeleteRole(Guid id)
        {
            var role = await baseDomainService.DeleteAsync(id);
            if (!role.IsSuccess)
            {
                return DomainResult<AppRole>.Error(role.Message);
            }
            return DomainResult<AppRole>.Success(role.Data);
        }
        //软删除角色
        public async Task<DomainResult<AppRole>> DisableRole(Guid id)
        {
            var role = await baseDomainService.DisableAsync(id);
            if (!role.IsSuccess)
            {
                return DomainResult<AppRole>.Error(role.Message);
            }
            return DomainResult<AppRole>.Success(role.Data);
        }
        //启用 / 禁用
        public async Task<DomainResult<AppRole>> EnableRole(Guid id)
        {
            var role = await baseDomainService.EnableAsync(id);
            if (!role.IsSuccess)
            {
                return DomainResult<AppRole>.Error(role.Message);
            }
            return DomainResult<AppRole>.Success(role.Data);
        }
    }
}
